package demo.structrue.tree;

public class TreeBs<E extends Comparable<E>> {
    public static void main(String[] args) {
        TreeBs<Integer> bs = new TreeBs<>();
        bs.addNode(33);
        bs.addNode(10);
        bs.addNode(40);
        bs.addNode(88);
        bs.addNode(11);
        bs.addNode(5);
        System.out.println("xx");

    }


    private class Node implements Comparable<Node> {
        public E e;
        public Node left, right;

        public Node(E e) {
            this.e = e;
            left = null;
            right = null;
        }

        @Override
        public int compareTo(Node o) {
            return this.e.compareTo(o.e);
        }
    }


    private Node root = null;
    private int size = 0;

    public TreeBs() {

    }

    public int size() {
        return size;
    }


    public boolean isEmpty() {
        return size == 0;
    }

    public void addNode(E e) {
        Node newNode = new Node(e);
        if (root == null) {
            root = newNode;
            size++;
        } else {
            addNode(root, newNode);
        }
    }

    private void addNode(Node rnode, Node tnode) {
        if (rnode.compareTo(tnode) <= 0) {
            if (rnode.right == null) {
                rnode.right = tnode;
                size++;
                return;
            }
            addNode(rnode.right, tnode);
        } else if (rnode.compareTo(tnode) > 0) {
            if (rnode.left == null) {
                rnode.left = tnode;
                size++;
                return;
            }
            addNode(rnode.left, tnode);
        }
    }




}
